package com.css.fxfzfxqh.modules.seismicHazardData.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import com.css.fxfzfxqh.base.attachment.entity.AttachmentInfoEntity;
import com.css.fxfzfxqh.base.attachment.service.AttachmentInfoService;
import com.css.fxfzfxqh.base.response.RestResponse;
import com.css.fxfzfxqh.constants.IntensityEnum;
import com.css.fxfzfxqh.constants.YNEnum;
import com.css.fxfzfxqh.modules.seismicHazardData.entity.ArModelEntity;
import com.css.fxfzfxqh.modules.seismicHazardData.entity.SettingInfluenceFliedEntity;
import com.css.fxfzfxqh.modules.seismicHazardData.entity.SettingSeismicProcessEntity;
import com.css.fxfzfxqh.modules.seismicHazardData.param.arModel.ArModelPageParam;
import com.css.fxfzfxqh.modules.seismicHazardData.param.arModel.CountParam;
import com.css.fxfzfxqh.modules.seismicHazardData.repository.SeismicImpactFieldRepository;
import com.css.fxfzfxqh.modules.seismicHazardData.service.SeismicImpactFieldService;
import com.css.fxfzfxqh.modules.seismicHazardData.utils.EarthquakeImpactFieldUtils;
import com.css.fxfzfxqh.util.*;
import com.css.fxfzfxqh.web.PlatformSessionContext;
import com.css.fxfzfxqh.zcpt.sys.entity.SUser;
import com.css.fxfzfxqh.zcpt.sys.service.SUserService;
import com.css.fxfzfxqh.zcpt.sys.service.SysAreaService;
import com.sun.istack.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.concurrent.TimeUnit;

@Service
@Slf4j
public class SeismicImpactFieldServiceImpl implements SeismicImpactFieldService {

    @Autowired
    private SeismicImpactFieldRepository seismicImpactFieldRepository;

    @Autowired
    private SUserService userService;

    @Autowired
    private SysAreaService sysAreaService;

    @Autowired
    private AttachmentInfoService attachmentInfoService;

    @Value("${image.localDir}")
    private String localDir;

    @Autowired
    private RedisTemplate redisTemplate;

    private final String YXC_KEY = "fxqh:yxcVersion";

    @Override
    public RestResponse saveArModel(ArModelEntity entity) {
        String user = userService.getSUser(PlatformSessionContext.getUserID());
        SUser sUser = CreateGson.createGson().fromJson(user, SUser.class);

        entity.setId(UUIDGenerator.getUUID());
        entity.setCreateUserId(PlatformSessionContext.getUserID());
        entity.setCreateUserName(sUser.getUserName());
        entity.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
        entity.setDelFlag("0");
        entity.setOrgId(sUser.getOrgId());
        entity.setOrgName(sUser.getOrgName());
        seismicImpactFieldRepository.saveArModel(entity);
        return RestResponse.succeed("新增模型成功!");
    }

    @Override
    public RestResponse deleteById(String id) {
        seismicImpactFieldRepository.deleteById(id);
        return RestResponse.succeed("删除模型成功!");
    }

    @Override
    public RestResponse page(ArModelPageParam param, HttpServletRequest request) {
        int page = Integer.valueOf(request.getParameter(PlatformPageUtils.CUR_PAGE));
        int size = Integer.valueOf(request.getParameter(PlatformPageUtils.PAGE_SIZE));
        Map<String, Object> data = seismicImpactFieldRepository.page(param, page, size);
        return RestResponse.succeed(data);
    }

    @Override
    public RestResponse getById(String id) {
        ArModelEntity entity = seismicImpactFieldRepository.getById(id);
        if (entity != null) {
            entity.setProvince(sysAreaService.getAreaNameByAreaId(entity.getProvince()));
            if (!entity.getCity().equals("全部")) {
                entity.setCity(sysAreaService.getAreaNameByAreaId(entity.getCity()));
            }
            return RestResponse.succeed(entity);
        }
        return RestResponse.succeed(new ArModelEntity());
    }

    @Override
    public RestResponse updateById(ArModelEntity entity) {
        String user = userService.getSUser(PlatformSessionContext.getUserID());
        SUser sUser = CreateGson.createGson().fromJson(user, SUser.class);

        entity.setUpdateTime(PlatformDateUtils.getCurrentTimestamp());
        entity.setUpdateUserId(PlatformSessionContext.getUserID());
        entity.setCreateUserName(sUser.getUserName());
        entity.setOrgName(sUser.getOrgName());
        entity.setOrgId(sUser.getOrgId());
        seismicImpactFieldRepository.updateById(entity);
        return RestResponse.succeed("修改模型成功!");
    }

    @Override
    public RestResponse countInfluenceField(CountParam param) {
        String userId = PlatformSessionUtils.getUserId();
        String user = userService.getSUser(userId);
        SUser sUser = CreateGson.createGson().fromJson(user, SUser.class);
        //模型
        ArModelEntity modelEntity = seismicImpactFieldRepository.getById(param.getId());
        //地震烈度衰减关系模型
        BigDecimal long_ratio1 = modelEntity.getLongRatio1();
        BigDecimal long_ratio2 = modelEntity.getLongRatio2();
        BigDecimal long_ratio3 = modelEntity.getLongRatio3();
        BigDecimal long_ratio4 = modelEntity.getLongRatio4();
        String long_symbol = modelEntity.getLongSymbol();
        BigDecimal short_ratio1 = modelEntity.getShortRatio1();
        BigDecimal short_ratio2 = modelEntity.getShortRatio2();
        BigDecimal short_ratio3 = modelEntity.getShortRatio3();
        BigDecimal short_ratio4 = modelEntity.getShortRatio4();
        String short_symbol = modelEntity.getShortSymbol();

        BigDecimal formula_ratio1 = modelEntity.getFormulaRatio1();
        BigDecimal formula_ratio2 = modelEntity.getFormulaRatio1();
        //长短轴比例
        BigDecimal scale2 = modelEntity.getScale();

        String versionCode = getVersionCode(YXC_KEY);

        BigDecimal longX = BigDecimal.ZERO;
        BigDecimal shortY = BigDecimal.ZERO;

        //震级
        BigDecimal magnitude = param.getMagnitude();
        ArrayList<SettingInfluenceFliedEntity> list = new ArrayList<>();
        String uuid = UUIDGenerator.getUUID();
        //开始计算
        for (int i = 10; i > 5; i--) {
            boolean isNa = false;
            if (i == 10) {
                isNa = true;
            }
            SettingInfluenceFliedEntity settingInfluenceFliedEntity = new SettingInfluenceFliedEntity();

            settingInfluenceFliedEntity.setEarthquakeLevel(magnitude);
            settingInfluenceFliedEntity.setDzIntensity(String.valueOf(i));
            settingInfluenceFliedEntity.setDirection(param.getDirection());
            settingInfluenceFliedEntity.setMagnitude(magnitude);
            settingInfluenceFliedEntity.setLongitude(param.getLongitude());
            settingInfluenceFliedEntity.setVersionCode(versionCode);
            settingInfluenceFliedEntity.setLatitude(param.getLatitude());
            settingInfluenceFliedEntity.setAssessUserName(sUser.getUserName());
            settingInfluenceFliedEntity.setDelFlag("0");
            //长轴：Ia=4.9024+1.3485M-3.9738Lg(Ra+13)
            //式中，Ia、Ib分别为长、短轴烈度，M为震级，Ra、Rb分别为烈度为I时长、短半轴的长度
            //根据公式计算得到Ra、Rb，如果值为负数，则舍掉，为正的则留下

            BigDecimal Ra = BigDecimal.ZERO;//烈度为Ia时长半轴的长度
            double a = (long_ratio1.add(long_ratio2.multiply(magnitude)).subtract(BigDecimal.valueOf(i)))
                    .divide(long_ratio3, 8, RoundingMode.UP).doubleValue();
            if ("ln".equals(long_symbol)) {
                Ra = BigDecimal.valueOf(Math.pow(Math.E, a)).subtract(long_ratio4);
            } else if ("lg".equals(long_symbol)) {
                Ra = BigDecimal.valueOf(Math.pow(10, a)).subtract(long_ratio4);
            }

            if (scale2.compareTo(BigDecimal.ZERO) > 0 && magnitude.compareTo(BigDecimal.valueOf(7)) > -1) {
                // 当使用破裂尺度公式且震级大于等于7.0级时，使用破裂尺度公式计算出长轴长度，根据长短轴比例计算出短轴长度。
                settingInfluenceFliedEntity.setDataSource("2");

                //M=5.08+1.16*lg(SRL)
                //M为震级,SRL为破裂尺度
                //根据公式计算得到SRL
                BigDecimal SRL = BigDecimal.valueOf(Math.pow(10, formula_ratio1.subtract(magnitude)
                        .divide(formula_ratio2, 8, RoundingMode.UP).doubleValue()));

                //最终的长轴长度=衰减关系计算的长轴+破裂尺度
                //最终的长轴长度=Ra*2+SRL
                //Ra为烈度为Ia时长半轴的长度,SRL为破裂尺度
                BigDecimal finalRa = Ra.multiply(BigDecimal.valueOf(2)).add(SRL);

                //最终的短轴长度
                BigDecimal finalRb = finalRa.divide(scale2, 2, RoundingMode.HALF_UP);

                if (finalRa.compareTo(BigDecimal.ZERO) < 0) {
                    //finalRa为负数
                    continue;
                }
                if (finalRb.compareTo(BigDecimal.ZERO) < 0) {
                    //finalRb为负数
                    continue;
                }
                finalRa = finalRa.setScale(1, RoundingMode.HALF_UP);//长轴长度
                finalRb = finalRb.setScale(1, RoundingMode.HALF_UP);//短轴长度
                settingInfluenceFliedEntity.setLongX(finalRa);
                settingInfluenceFliedEntity.setShortY(finalRb);
            } else {
                // 地震影响场可以使用烈度衰减模型进行模拟，当震级小于7.0级时使用椭圆衰减模型，
                settingInfluenceFliedEntity.setDataSource("1");

                // 短轴：Ib=4.3517+ 1.2192M-3.7429Lg(Rb+6)
                //式中，Ia、Ib分别为长、短轴烈度，M为震级，Ra、Rb分别为烈度为I时长、短半轴的长度
                //根据公式计算得到Ra、Rb，如果值为负数，则舍掉，为正的则留下

                BigDecimal Rb = BigDecimal.ZERO;//烈度为Ib时短半轴的长度
                double b = (short_ratio1.add(short_ratio2.multiply(magnitude)).subtract(BigDecimal.valueOf(i))).divide(short_ratio3, 8, RoundingMode.UP).doubleValue();
                if ("lg".equals(short_symbol)) {
                    Rb = BigDecimal.valueOf(Math.pow(10, b)).subtract(short_ratio4);
                } else if ("ln".equals(short_symbol)) {
                    Rb = BigDecimal.valueOf(Math.pow(Math.E, b)).subtract(short_ratio4);
                }
                if (Ra.compareTo(BigDecimal.ZERO) < 0) {
                    //Ra为负数
                    continue;
                }
                if (Rb.compareTo(BigDecimal.ZERO) < 0) {
                    //Rb为负数
                    continue;
                }
                Ra = Ra.multiply(BigDecimal.valueOf(2)).setScale(1, RoundingMode.HALF_UP);//长轴长度
                Rb = Rb.multiply(BigDecimal.valueOf(2)).setScale(1, RoundingMode.HALF_UP);//短轴长度
                settingInfluenceFliedEntity.setLongX(Ra);
                settingInfluenceFliedEntity.setShortY(Rb);
            }
            settingInfluenceFliedEntity.setId(UUIDGenerator.getUUID());
            settingInfluenceFliedEntity.setSourceEarthquakeId(uuid);

            String influenceEllipse = null;
            if (!isNa) {
                //环
                influenceEllipse = EarthquakeImpactFieldUtils.createInfluenceEllipse(settingInfluenceFliedEntity.getLongitude(),
                        settingInfluenceFliedEntity.getLatitude(), settingInfluenceFliedEntity.getLongX().toString(),
                        settingInfluenceFliedEntity.getShortY().toString(),
                        String.valueOf(settingInfluenceFliedEntity.getDirection()), longX.toString(), shortY.toString());
            } else {
                //椭圆
                influenceEllipse = EarthquakeImpactFieldUtils.createInfluenceEllipse(settingInfluenceFliedEntity.getLongitude(),
                        settingInfluenceFliedEntity.getLatitude(), settingInfluenceFliedEntity.getLongX().toString(),
                        settingInfluenceFliedEntity.getShortY().toString(),
                        String.valueOf(settingInfluenceFliedEntity.getDirection()), null, null);
            }
            isNa = false;
            longX = settingInfluenceFliedEntity.getLongX();
            shortY = settingInfluenceFliedEntity.getShortY();
            settingInfluenceFliedEntity.setGeom(influenceEllipse);
            settingInfluenceFliedEntity.setIntensityCh(IntensityEnum.getByCode(i));
            settingInfluenceFliedEntity.setAssessUserId(userId);
            settingInfluenceFliedEntity.setAssessUserDept(sUser.getOrgId());
            settingInfluenceFliedEntity.setAssessTime(PlatformDateUtils.getCurrentTimestamp());
            list.add(settingInfluenceFliedEntity);
        }
        if (list.size() != 0) {
            list.forEach(it -> {
                seismicImpactFieldRepository.saveSettingInfluenceFlied(it, 0);
            });
        }
        return RestResponse.succeed(list);
    }

    public synchronized String getVersionCode(@NotNull String key) {
        String versionCode = "";
        if (redisTemplate.opsForValue().get(key) == null) {
            versionCode = "001";
        } else {
            versionCode = redisTemplate.opsForValue().get(key).toString();
            StringBuilder stringBuilder = new StringBuilder();
            String t = String.valueOf(Integer.parseInt(versionCode) + 1);
            for (int i = t.length(); i < 3; i++) {
                stringBuilder.append("0");
            }
            versionCode = stringBuilder.append(t).toString();
        }
        redisTemplate.opsForValue().set(key, versionCode, getRemainSecondsOneDay(DateUtil.date()), TimeUnit.SECONDS);
        String date = DateUtil.today().replaceAll("-", "");
        versionCode = date + "YXC" + versionCode;
        return versionCode;
    }

    /**
     * 当前时间距离凌晨12点的秒数
     *
     * @param currentDate
     * @return
     */
    public static Integer getRemainSecondsOneDay(Date currentDate) {
        //使用plusDays加传入的时间加1天，将时分秒设置成0
        LocalDateTime midnight = LocalDateTime.ofInstant(currentDate.toInstant(),
                        ZoneId.systemDefault()).plusDays(1).withHour(0).withMinute(0)
                .withSecond(0).withNano(0);
        LocalDateTime currentDateTime = LocalDateTime.ofInstant(currentDate.toInstant(),
                ZoneId.systemDefault());
        //使用ChronoUnit.SECONDS.between方法，传入两个LocalDateTime对象即可得到相差的秒数
        long seconds = ChronoUnit.SECONDS.between(currentDateTime, midnight);
        return (int) seconds;
    }

    @Override
    public RestResponse countSettingSeismicProcess(SettingSeismicProcessEntity entity) {
        entity.setId(UUIDGenerator.getUUID());
        String userId = PlatformSessionContext.getUserID();
        entity.setCreateUserId(userId);
        String versionCode = getVersionCode(YXC_KEY);
        String user = userService.getSUser(userId);
        SUser sUser = CreateGson.createGson().fromJson(user, SUser.class);
        entity.setCreateUser(sUser.getUserName());
        entity.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
        entity.setDelFlag(YNEnum.N.toString());

        String uuid = UUIDGenerator.getUUID();

        boolean isNa = false;
        BigDecimal longX1 = BigDecimal.ZERO;
        BigDecimal shortY1 = BigDecimal.ZERO;
        //烈度,遍历烈度
        int I2 = 10;
        switch (entity.getEpicenterIntensity()) {
            case "Ⅹ":
                I2 = 10;
                break;
            case "Ⅸ":
                I2 = 9;
                break;
            case "Ⅷ":
                I2 = 8;
                break;
            case "Ⅶ":
                I2 = 7;
                break;
            case "Ⅵ":
                I2 = 6;
                break;
        }

        //开始计算
        BigDecimal M = entity.getMagnitude(); //震级

        isNa = true;
        ArrayList<SettingInfluenceFliedEntity> list = new ArrayList<>();
        for (int I = I2; I > 5; I--) {
            SettingInfluenceFliedEntity influenceflied = new SettingInfluenceFliedEntity();
            influenceflied.setEarthquakeLevel(M);
            influenceflied.setDzIntensity(String.valueOf(I));
            influenceflied.setAssessUserName(sUser.getUserName());
            influenceflied.setDataSource("2");//2手动录入
            BigDecimal longX = BigDecimal.ZERO;
            BigDecimal shortY = BigDecimal.ZERO;
            switch (I) {
                case 10:
                    longX = entity.getLongLength5();
                    shortY = entity.getShortLength5();
                    break;
                case 9:
                    longX = entity.getLongLength4();
                    shortY = entity.getShortLength4();
                    break;
                case 8:
                    longX = entity.getLongLength3();
                    shortY = entity.getShortLength3();
                    break;
                case 7:
                    longX = entity.getLongLength2();
                    shortY = entity.getShortLength2();
                    break;
                case 6:
                    longX = entity.getLongLength1();
                    shortY = entity.getShortLength1();
                    break;
            }
            influenceflied.setLongX(longX);
            influenceflied.setShortY(shortY);
            influenceflied.setId(UUIDGenerator.getUUID());

            String influenceEllipse = null;
            if (!isNa) {
                //环
                influenceEllipse = EarthquakeImpactFieldUtils.createInfluenceEllipse(entity.getLongitude(),
                        entity.getLatitude(), influenceflied.getLongX().toString(),
                        influenceflied.getShortY().toString(),
                        String.valueOf(entity.getDirection()), longX1.toString(), shortY1.toString());
            } else {
                //椭圆
                influenceEllipse = EarthquakeImpactFieldUtils.createInfluenceEllipse(entity.getLongitude(),
                        entity.getLatitude(), influenceflied.getLongX().toString(),
                        influenceflied.getShortY().toString(),
                        String.valueOf(entity.getDirection()), null, null);
            }
            isNa = false;
            longX1 = influenceflied.getLongX();
            shortY1 = influenceflied.getShortY();
            influenceflied.setGeom(influenceEllipse);

            influenceflied.setSourceEarthquakeId(uuid);
            influenceflied.setAssessUserId(userId);
            influenceflied.setAssessUserDept(sUser.getOrgId());
            influenceflied.setAssessTime(PlatformDateUtils.getCurrentTimestamp());
            influenceflied.setLongitude(entity.getLongitude());
            influenceflied.setLatitude(entity.getLatitude());
            influenceflied.setDirection(entity.getDirection());
            influenceflied.setIntensityCh(IntensityEnum.getByCode(I));
            influenceflied.setDelFlag("0");
            influenceflied.setVersionCode(versionCode);

            list.add(influenceflied);
            seismicImpactFieldRepository.saveSettingInfluenceFlied(influenceflied, 1);
        }
        entity.setCreateTime(PlatformDateUtils.getCurrentDate());
        entity.setCreateUser(sUser.getUserName());
        entity.setCreateUserId(PlatformSessionUtils.getUserId());
        entity.setDelFlag("0");
        entity.setId(UUIDGenerator.getUUID());
        entity.setEarthquakeImpactFieldId(uuid);
        seismicImpactFieldRepository.saveSettingSeismicProcess(entity);
        return RestResponse.succeed(list);
    }

    @Override
    public RestResponse importShp(String attachIds) {
        String userId = PlatformSessionContext.getUserID();
        String versionCode = getVersionCode(YXC_KEY);
        String user = userService.getSUser(userId);
        SUser sUser = CreateGson.createGson().fromJson(user, SUser.class);
        Map<String, Object> map = new HashMap<>();
        this.uniformFileName(attachIds);
        ParsingResult shpData = getShpData(attachIds);
        //是否成功
        if (!shpData.getMessage().equals("ok")) {
            map.put("res", false);
            map.put("mess", shpData.getMessage());
        }
        List<List<Object>> shpList = shpData.getShpList();
        String uuid = UUIDGenerator.getUUID();
        ArrayList<SettingInfluenceFliedEntity> resultList = new ArrayList<>();
        for (int i = 0; i < shpList.size(); i++) {
            List<Object> list = shpList.get(i);

            SettingInfluenceFliedEntity entity = new SettingInfluenceFliedEntity();
            entity.setAssessUserId(PlatformSessionContext.getUserID());
            entity.setAssessTime(PlatformDateUtils.getCurrentTimestamp());
            entity.setId(UUIDGenerator.getUUID());
            entity.setSourceEarthquakeId(UUIDGenerator.getUUID());
            if (!PlatformObjectUtils.isEmpty(list.get(0))) {
                entity.setGeom(list.get(0).toString());
            }
            if (!PlatformObjectUtils.isEmpty(list.get(3))) {
                entity.setDzIntensity(extractingNumbers(list.get(3).toString()));
            }
            if (!PlatformObjectUtils.isEmpty(list.get(4))) {
                entity.setIntensityCh(list.get(4).toString());
            }
            if (!PlatformObjectUtils.isEmpty(list.get(7))) {
                entity.setMagnitude(new BigDecimal(list.get(7).toString()));
            }
            if (!PlatformObjectUtils.isEmpty(list.get(8))) {
                entity.setLongX(new BigDecimal(list.get(8).toString()));
            }
            if (!PlatformObjectUtils.isEmpty(list.get(9))) {
                entity.setShortY(new BigDecimal(list.get(9).toString()));
            }
            entity.setAssessUserName(sUser.getUserName());
            entity.setAssessUserId(userId);
            entity.setDelFlag("0");
            entity.setDataSource("3");
            entity.setSourceEarthquakeId(uuid);
            entity.setVersionCode(versionCode);
            seismicImpactFieldRepository.saveSettingInfluenceFlied(entity, 0);
            resultList.add(entity);
        }
        return RestResponse.succeed(resultList);
    }


    /**
     * 获取 字符串中的数字
     *
     * @param dzIntensity
     * @return
     */
    private static String extractingNumbers(String dzIntensity) {
        dzIntensity = dzIntensity.trim();
        String str2 = "";
        if (dzIntensity != null && !"".equals(dzIntensity)) {
            for (int i = 0; i < dzIntensity.length(); i++) {
                if (dzIntensity.charAt(i) >= 48 && dzIntensity.charAt(i) <= 57) {
                    str2 += dzIntensity.charAt(i);
                }
            }
        }
        return str2;
    }

    public void uniformFileName(String fileIds) {
        String[] idList = fileIds.split(",");
        AttachmentInfoEntity attachRoot = attachmentInfoService.getAttach(idList[0]);
        String attachRootPath = attachRoot.getAttachPath();
        String filePathCurrTime = getFilePathCurrTime(attachRootPath);
        for (int i = 1; i < idList.length; i++) {
            AttachmentInfoEntity attach = attachmentInfoService.getAttach(idList[i]);
            if (getFilePathCurrTime(attach.getAttachPath()).equals(filePathCurrTime)) {
                continue;
            }
            String attachPath = attach.getAttachPath();
            String fileDiskPath = localDir + attachPath;
            cn.hutool.core.io.FileUtil.rename(new File(fileDiskPath), getNonSuffixFileName(attach.getAttachName()) + "_" + filePathCurrTime + "." + cn.hutool.core.io.FileUtil.getSuffix(attach.getAttachName()), true);
            String[] s = attachPath.split("_");
            attach.setAttachPath(s[0] + "_" + filePathCurrTime + "." + FileUtil.getSuffix(attach.getAttachName()));
            attachmentInfoService.update(attach);
        }
    }

    public ParsingResult getShpData(String fileIds) {
        //.prj结尾用来校验是否为2000坐标系
        String prj = "";
        //.cpg文件用来获得编码格式,例如utf-8
        String cpg = "";
        //.shp文件用来获得数据
        String shp = "";
        //根据id获取真实地址
        String[] split = fileIds.split(",");
        for (String id : split) {
            //根据id和文件名获取真实的放在磁盘上的文件
            AttachmentInfoEntity attachmentInfoEntity = attachmentInfoService.getAttach(id);
            String attachPath = attachmentInfoEntity.getAttachPath();
            String substring = attachPath.substring(attachPath.length() - 4);
            if (substring.equals(".prj")) {
                prj = localDir + File.separator + attachPath;
            } else if (substring.equals(".cpg")) {
                cpg = localDir + File.separator + attachPath;
            } else if (substring.equals(".shp")) {
                shp = localDir + File.separator + attachPath;
            }
        }
        return ShpAnalyticUtil.analytic(prj, cpg, shp);
    }

    private String getFilePathCurrTime(String filePath) {
        return filePath.split("_")[1].replaceAll("." + FileUtil.getSuffix(filePath.split("_")[1]), "");
    }

    private String getNonSuffixFileName(String fileName) {
        return fileName.replaceAll("." + FileUtil.getSuffix(fileName), "");
    }

    @Override
    public RestResponse getAll(HttpServletRequest request) {
        int page = Integer.valueOf(request.getParameter(PlatformPageUtils.CUR_PAGE));
        int size = Integer.valueOf(request.getParameter(PlatformPageUtils.PAGE_SIZE));
        return RestResponse.succeed(seismicImpactFieldRepository.getAll(page, size));
    }

    @Override
    public RestResponse getInfluencefliedById(String versionCode) {
        return RestResponse.succeed(seismicImpactFieldRepository.getInfluencefliedById(versionCode));
    }

    @Override
    public void deleteInfluencefliedById(String versionCode) {
        seismicImpactFieldRepository.deleteInfluencefliedById(versionCode);
    }
}
